package com.hzbat.controller; 																

import java.util.List;

import javax.validation.Valid;

import org.slf4j.Logger;		
import org.slf4j.LoggerFactory;		
import org.springframework.beans.factory.annotation.Autowired;							  
import org.springframework.stereotype.Controller;										  
import org.springframework.validation.BindingResult;										  
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;							  
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;						      	  

import com.hzbat.entity.PmHzbatBatchesInfo;													  
import com.hzbat.form.PmHzbatBatchesInfoFrom;
import com.hzbat.response.DataResponse;													  
import com.hzbat.response.FormResponse;													  
import com.hzbat.response.PageResponse;													  
import com.hzbat.response.SimpleResponse;													  
import com.hzbat.service.PmHzbatBatchesInfoService;												  
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;												  


@Controller 																				  
@RequestMapping("pmHzbatBatchesInfo")															  
public class PmHzbatBatchesInfoController extends BasicController{  														  
	   
	    private static Logger logger = LoggerFactory.getLogger(PmHzbatBatchesInfoController.class);	  
		
		@Autowired																			  
		PmHzbatBatchesInfoService pmHzbatBatchesInfoServiceImpl ;															  
	 	
		
		/**																					  
		 * 获取单个计划下的所有批量，包含批量关系																			  
		 * @param pmHzbatBatchesInfo															  
		 * @return																		      
		 */																					  
		@ResponseBody																		  
		@RequestMapping("/getScheduleBatches")															  
		public DataResponse<List<List<PmHzbatBatchesInfo>>> getScheduleBatches(PmHzbatBatchesInfo pmHzbatBatchesInfo){				  
			logger.info("获取单个计划下的所有批量，包含批量关系--->"+pmHzbatBatchesInfo.toString());						  
			List<List<PmHzbatBatchesInfo>> data = pmHzbatBatchesInfoServiceImpl.getScheduleBatches(pmHzbatBatchesInfo);		                          
			DataResponse<List<List<PmHzbatBatchesInfo>>> response = new DataResponse<List<List<PmHzbatBatchesInfo>>>();	      
			response.setData(data);		                                                      
			return response ;		                                                          
		}
		
		
    	/**   																				  
    	 * 跳转到明细页面   																		  
    	 * @param id   																		  
    	 * @return   																		  
    	 */   																				  
    	@RequestMapping("/detail")   														  
    	public String toDetail(String id){   												  
    		logger.info("跳转到明细页面-->pm_hzbat_batches_info_detail.jsp");  									  
    		return "pm_hzbat_batches_info_detail";   													  
    	}  
    	
    	 																				  
		/***		  																		  
		 * 查询列表		  																	  
		 * @param user		  																  
		 * @return		  																	  
		 */		  																		      
		@ResponseBody	  																	  
		@RequestMapping("/getList")	  													  
		public PageResponse<PmHzbatBatchesInfo> getList(PmHzbatBatchesInfo pmHzbatBatchesInfo){  			  
			logger.info("获取数据列表--->"+pmHzbatBatchesInfo.toString());  						  
			PageInfo<PmHzbatBatchesInfo> page = pmHzbatBatchesInfoServiceImpl.getPage(pmHzbatBatchesInfo);  				  
			PageResponse<PmHzbatBatchesInfo> response = new PageResponse<PmHzbatBatchesInfo>() ;	  	  
			response.setData(page);  														  
			return response ;  																  
		}  	
		
																						  
		/**																					  
		 * 查询单条																			  
		 * @param pmHzbatBatchesInfo															  
		 * @return																		      
		 */																					  
		@ResponseBody																		  
		@RequestMapping("/get")															  
		public DataResponse<PmHzbatBatchesInfo> get(PmHzbatBatchesInfo pmHzbatBatchesInfo){				  
			logger.info("获取单条数据--->"+pmHzbatBatchesInfo.toString());						  
			PmHzbatBatchesInfo data = pmHzbatBatchesInfoServiceImpl.get(pmHzbatBatchesInfo);		                          
			DataResponse<PmHzbatBatchesInfo> response = new DataResponse<PmHzbatBatchesInfo>();	      
			response.setData(data);		                                                      
			return response ;		                                                          
		}	
		
																						  
		/*** 																	              
		 * 新增 																			      
		 * @param pmHzbatBatchesInfo 															  
		 */  																				  
		@ResponseBody  																		  
		@RequestMapping("/add")  															  
		public FormResponse<String> add(@Valid PmHzbatBatchesInfo pmHzbatBatchesInfo,BindingResult result){  					  
			logger.info("新增数据-->"+pmHzbatBatchesInfo.toString());  							  
			FormResponse<String> response = handleErrorResule(result);  		  			  
			if(response.isSuccess()){  														  
				pmHzbatBatchesInfoServiceImpl.add(pmHzbatBatchesInfo);  												  
				response.setMessage("新增成功！");  											  
			}else{ 																			  
				response.setMessage("新增失败！");  											  
			}  																				  
			return response;  															      
		}  
																							  
		/***  																				  
		 * 修改 																			      
		 * @param pmHzbatBatchesInfo  															  
		 */  																				  
		@ResponseBody  																		  
		@RequestMapping("/update")  														  
		public FormResponse<Void> update(@Valid PmHzbatBatchesInfo pmHzbatBatchesInfo,BindingResult result){  					  
			logger.info("修改数据-->"+pmHzbatBatchesInfo.toString());  							  
			FormResponse<Void> response = handleErrorResule(result);  						  
			if(response.isSuccess()){  														  
				pmHzbatBatchesInfoServiceImpl.update(pmHzbatBatchesInfo);  											  
				response.setMessage("修改成功！");  											  
			}else{  																		  
				response.setMessage("修改失败！");  											  
			}  																				  
			return response;  																  
		}  	
																						  
		/**  																				  
		 * 删除  																			      
		 * @param pmHzbatBatchesInfo  															  
		 */  																				  
		@ResponseBody  																		  
		@RequestMapping("/del") 															  
		public SimpleResponse<Void> delete(PmHzbatBatchesInfo pmHzbatBatchesInfo){  					  
			logger.info("删除数据-->"+pmHzbatBatchesInfo.toString());  							  
			SimpleResponse<Void> response = new SimpleResponse<Void>();  					  
			pmHzbatBatchesInfoServiceImpl.delete(pmHzbatBatchesInfo);  												  
			response.setSuccess(true);  													  
			return response;  																  
		}		 																			  
 
	    /***
	     * 保存多组批量信息
	     * @param form
	     * @return
	     */
		
		@ResponseBody
		@RequestMapping("/saveNodes")
		public FormResponse<Void> saveNodes(String form){
			FormResponse<Void> response = new FormResponse<Void>();
			List<PmHzbatBatchesInfo> list = JSON.parseArray(form, PmHzbatBatchesInfo.class);
			for(PmHzbatBatchesInfo pb:list){
				System.out.println(pb.toString());
				pmHzbatBatchesInfoServiceImpl.add(pb);
			}
			return response ;
		}
	 
	 
	}  



